Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[menu-button] Prevent default for links to avoid double click events #812

Merged
merged 1 commit into from
Jun 28, 2021

Conversation

IanVS
Copy link
Contributor

@IanVS IanVS commented Jun 25, 2021

Thank you for contributing to Reach UI! Please fill in this template before submitting your PR to help us process your request more quickly.

  • Use a meaningful title for the pull request. Include the name of the package modified.
  • Test the change in your own code (Compile and run).
  • Add or edit tests to reflect the change (Run with yarn test).
  • Add or edit Storybook examples to reflect the change (Run with yarn start).
  • Ensure formatting is consistent with the project's Prettier configuration.
  • Add documentation to support any new features.

This pull request:

  • Creates a new package
  • Fixes a bug in an existing package
  • Adds additional features/functionality to an existing package
  • Updates documentation or example code
  • Other

Fixes #811.

I found that without preventing the original event's default, I was getting two click events, and one would fire inside a Dialog that I was opening, immediately closing it. This ensures the original event is prevented when creating a new .click() on a link.

@codesandbox-ci
Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 8a89495:

Sandbox Source
reach-ui-template Configuration
silly-rgb-kxqw6 Issue #811

@IanVS
Copy link
Contributor Author

IanVS commented Jun 25, 2021

Oh wow, the codesandbox bot is awesome. It forked my reproduction from the issue and applied these changes? That's very cool, and a good way to show that the problem is fixed.

@@ -662,10 +662,10 @@ const MenuItems = React.forwardRef(function MenuItems(
// consistent behavior across menu items we'll trigger a click when
// the spacebar is pressed.
if (selected) {
event.preventDefault();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@IanVS Should this not be moved into the next if block? I don't think we want to preventDefault for buttons.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah nope, I'm totally wrong here since we were doing that already! Gonna poke around a bit for any unintended edge cases here.

@chaance chaance added the Type: Bug Something isn't working label Jun 28, 2021
@chaance chaance merged commit 630f631 into reach:develop Jun 28, 2021
@IanVS IanVS deleted the 811-prevent-double-click branch June 28, 2021 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[MenuLink] Immediately clicks button inside Dialog when using keyboard
2 participants